#include "CPunt3D.h"
#include <math.h>

// Constructors
//-----------------------------------------------------------
CPunt3D::CPunt3D( void ) : x( 0 ), y( 0 ), z( 0 ) {}

CPunt3D::CPunt3D( const CPunt3D &init ){
	this->x = init.x;
	this->y = init.y;
	this->z = init.z;
}

CPunt3D::CPunt3D( float x, float y, float z ) : x( x ), y( y ), z( z ) {}

CPunt3D::~CPunt3D( void ) {}


// Escriptura de dades
//-----------------------------------------------------------
void CPunt3D::setPunt3D( CPunt3D &punt ){
	this->x = punt.getPunt3DX();
	this->y = punt.getPunt3DY();
	this->z = punt.getPunt3DZ();
}

void CPunt3D::setPunt3D( float x, float y, float z ){
	this->x = x;
	this->y = y;
	this->z = z;
}

void CPunt3D::setPunt3DX( float x ){
	this->x = x;
}

void CPunt3D::setPunt3DY( float y ){
	this->y = y;
}

void CPunt3D::setPunt3DZ( float z ){
	this->z = z;
}


// Lectura de dades
//-----------------------------------------------------------
CPunt3D & CPunt3D::getPunt3D( void ){
	return *this;
}

float CPunt3D::getPunt3DX( void ){
	return this->x;
}

float CPunt3D::getPunt3DY( void ){
	return this->y;
}

float CPunt3D::getPunt3DZ( void ){
	return this->z;
}


// Operacions
//-----------------------------------------------------------
CPunt3D CPunt3D::operator + ( CPunt3D suma ){
	CPunt3D tmp;
	tmp.setPunt3D( this->x + suma.getPunt3DX(), this->y + suma.getPunt3DY(), this->z + suma.getPunt3DZ() );
	return tmp;
}

CPunt3D CPunt3D::operator += ( CPunt3D suma ){
	this->x += suma.getPunt3DX();
	this->y += suma.getPunt3DY();
	this->z += suma.getPunt3DZ();
	return *this;
}

CPunt3D CPunt3D::operator ++ ( void ){
	this->x++;
	this->y++;
	this->z++;
	return *this;
}

CPunt3D CPunt3D::operator - ( CPunt3D resta ){
	CPunt3D tmp;
	tmp.setPunt3D( this->x - resta.getPunt3DX(), this->y - resta.getPunt3DY(), this->z - resta.getPunt3DZ() );
	return tmp;
}

CPunt3D CPunt3D::operator -= ( CPunt3D resta ){
	this->x -= resta.getPunt3DX();
	this->y -= resta.getPunt3DY();
	this->z -= resta.getPunt3DZ();
	return *this;
}

CPunt3D CPunt3D::operator -- ( void ){
	this->x--;
	this->y--;
	this->z--;
	return *this;
}

float CPunt3D::operator * ( CPunt3D escalar ){
	return ( this->x * escalar.getPunt3DX() + this->y * escalar.getPunt3DY() + this->z * escalar.getPunt3DZ() );
}

CPunt3D CPunt3D::operator / ( float div ){
	CPunt3D tmp;
	tmp.setPunt3D( this->x / div, this->y / div, this->z / div );
	return tmp;
}

CPunt3D CPunt3D::operator /= ( float div ){
	this->x /= div;
	this->y /= div;
	this->z /= div;
	return *this;
}

CPunt3D CPunt3D::doVectorial( CPunt3D vectorial ){
	CPunt3D tmp;
	tmp.setPunt3D( this->y * vectorial.getPunt3DZ() - this->z * vectorial.getPunt3DY(),
		this->z * vectorial.getPunt3DX() - this->x * vectorial.getPunt3DZ(),
		this->x * vectorial.getPunt3DY() - this->y * vectorial.getPunt3DX() );
	return tmp;
}

CPunt3D CPunt3D::doVectorialMOD( CPunt3D vectorial ){
	CPunt3D tmp;
	tmp.setPunt3D( this->y * vectorial.getPunt3DZ() - this->z * vectorial.getPunt3DY(),
		this->z * vectorial.getPunt3DX() - this->x * vectorial.getPunt3DZ(),
		this->x * vectorial.getPunt3DY() - this->y * vectorial.getPunt3DX() );
	this->x = tmp.getPunt3DX();
	this->y = tmp.getPunt3DY();
	this->z = tmp.getPunt3DZ();
	return *this;
}

CPunt3D CPunt3D::doNormalitzar( void ){
	float modul = sqrt( pow( this->x, 2 ) + pow( this->y, 2 ) + pow( this->z, 2 ) );
	this->x /= modul;
	this->y /= modul;
	this->z /= modul;
	return *this;
}